﻿@using PureLib.Common
@using WhereAreThem.Model.Models
@using WhereAreThem.WebViewer.Models
@model List<SearchResult>
@{
    string machineName = ViewBag.MachineName;
    ViewBag.Title = Extensions.ActionSearchResult;
}

@using (Html.BeginForm()) {
    <div class="header">
        @Html.TextBox("searchPattern", null, new { @class = "search" })
        <div class="navigation">
            <div class="machineName">
                <a href="@Url.Action(Extensions.ActionExplorer, new { machineName = machineName })">@machineName</a>
            </div>
            <div class="navigationItem">
                <span class="icon separator"></span>
            </div>
            <div class="navigationItem">
                Search Results in 
            </div>
        </div>
    </div>
}

<table class="viewer result">
    <thead>
        <tr>
            <th class="name">Name</th>
            <th class="size">Size</th>
            <th class="location">Location</th>
        </tr>
    </thead>
    <tbody>
        @if (Model.Count == 0) {
            <tr>
                <td colspan="3"><div class="empty">Empty</div></td>
            </tr>
        }
        else {
            foreach (SearchResult r in Model) {
                <tr>
                    @if (r.Item is Folder) {
                        Folder f = (Folder)r.Item;
                        <td>
                            <a href="@Url.Action(Extensions.ActionExplorer, new { machineName = machineName, path = Path.Combine(r.ItemPath, f.Name) })">
                                <span class="icon folder item iconText">@f.Name</span>
                            </a>
                        </td>
                    }
                    else {
                        WhereAreThem.Model.Models.File f = (WhereAreThem.Model.Models.File)r.Item;
                        <td>
                            <span class="icon file item iconText">@f.Name</span>
                        </td>
                    }
                    <td class="size nowrap">@r.Item.Size.ToFriendlyString()</td>
                    <td class="location">
                        <a href="@Url.Action(Extensions.ActionExplorer, new { machineName = machineName, path = r.ItemPath })">
                            <span class="item">@r.ItemPath</span>
                        </a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>

<script type="text/javascript">
    $(document).ready(function () {
        var location = getUrlParameter('path');
        document.title += @Html.Raw("'".GetTitle("' + location + '", machineName))';
        $('div.navigationItem:last').append('<a href="@Url.Action(Extensions.ActionExplorer)?machineName=@machineName&path=' + location + '"><span>' + location + '</span></a>');
    });
</script>